** Preamble **
 
clear all
set more off

local path_input  "C:/Users/$user/Dropbox/$project/master/output/data"
local path_output "C:/Users/$user/Dropbox/$project/master/output/tables"


* Note: local directory is the output folder 
cd "`path_output'"

use , clear



****PLACEBO
forvalues j=1/1000{
use "C:\Users\luism\Dropbox\Current projects\globo_debate\replication_package\master\output\data\dataset_final_june19.dta", clear

gen state=floor(codigo_ibge/10000)

forvalues i=11/52{
cap count if treatment==0 & state==`i' & turno==2
cap gen aux_`i'=r(N)
}

gen random=runiform(0,1)

sort state random

bysort state: gen id=_n

replace treatment=1

forvalues i=11/52{
replace treatment=0 if id<=aux_`i' & state==`i'
}


label var treatment "Globo=1"

xi: xtreg sh_Tpt_ treatment i.turno sh_Tpsp_-sh_Tpsdb_ T1*, vce(cluster codigo_ibge) fe

gen fake_treatment=_b[treatment]
duplicates drop fake_treatment, force
keep fake_treatment

save fake`j'.dta, replace
}

clear all
forvalues i=1/1000{
append using fake`i'
erase fake`i'.dta
}

cumul fake, gen(cum)

gen impact=-0.019

sort cum
twoway (line cum fake, ylab(, grid) ytitle("") xlab(, grid) ) || line cum impact

gen aux=runiform(0,1)
twoway (kdensity fake, ylab(, grid) bw(0.003) ytitle("") xlab(, grid) ) || line aux impact, yaxis(2)

